package com.example.project22_editingmediaplayer;

import java.util.ArrayList;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.example.minimusicdemo.Fragment_playlist;
import com.example.minimusicdemo.Fragment_playmain;
import com.example.minimusicdemo.Main_play;
import com.example.project22_editingmediaplayer.action.AudioUltility;
import com.example.project22_editingmediaplayer.adapter.RowSong;
import com.example.project22_editingmediaplayer.adapter.RowSongListAlbum;
import com.example.project22_editingmediaplayer.adapter.RowSongplaylistF;
import com.example.project22_editingmediaplayer.objects.SongObject;
import com.example.project22_editingmediaplayer.resource.SongResource;

public class ArtisListDetail extends Activity {
	private static RowSongListAlbum Adapter_artis;

	ListView listView_detail;
	AudioUltility audioultility;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.listplay_detail);
		listView_detail = (ListView) findViewById(R.id.lv_playlistdetail);

		SongResource.listSong = LayoutArtists.listArtistsong;
		Adapter_artis= new RowSongListAlbum(SongResource.listSong,
				getBaseContext());
		listView_detail.setAdapter(Adapter_artis);
		Adapter_artis.notifyDataSetChanged();

		listView_detail.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				MainActivity.mService.PlaySong(arg2);
              if(MainActivity.mService.getlistsong()!=null){
				SongResource.listSong.get(MainActivity.mService.getlastIndex())
						.set_isplay(false);}
				SongResource.listSong.get(MainActivity.mService.getIndex())
						.set_isplay(true);
				ArtisListDetail.Adapter_artis.notifyDataSetChanged();

			}
		});
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		getMenuInflater().inflate(R.menu.menuplayemotion, menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;
		case R.id.playall:
			SongResource.listSong = Adapter_artis.getAllData();
			Intent intent = new Intent(ArtisListDetail.this, Main_play.class);
			MainActivity.mService.PlaySong(0);
			MainActivity.mService.showNotification(0,
					SongResource.listSong.get(0));
			MainActivity.btnPlay
					.setImageResource(R.drawable.apollo_holo_light_pause);
			MainActivity.namesong.setText(SongResource.listSong.get(0)
					.get_name());
			MainActivity.singer.setText(SongResource.listSong.get(0)
					.get_artist());
			MainActivity.mService.flag_first = false;
			startActivity(intent);
			break;

		default:
			break;
		}
		return false;
	}

}
